package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.client.ProducerClient;
import cn.kgc.springcloud.entity.ResponseResult;
import cn.kgc.springcloud.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 课工场
 * @date 2024/7/22
 * @description
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

    @Resource
    private ProducerClient producerClient;

    @GetMapping("m1")
    public String method1(){

        //producer  method1   openfeign会发起http请求    get  http://localhost:8520/producer/m1
        String s = producerClient.method1();
        return "ConsumerController service ok  >>  producer >>"+s;
    }

    @GetMapping("m2")
    public String method2(Integer id){

        System.out.println("id = " + id);
        String s = producerClient.method2(id);

        return "ConsumerController service ok  >>  producer >>"+s;
    }

    @GetMapping("m3/{id}")
    public String method3(@PathVariable("id") Integer id){
        System.out.println("id = " + id);

        String s = producerClient.method3(id);

        return "ConsumerController service ok  >>  producer >>"+s;
    }


    // ? username = & password = & id =
    @GetMapping("m4")
    public String method4(User user){

        System.out.println("user = " + user);

        String s = producerClient.method4(user.getId(),user.getUsername(),user.getPassword());
        return "ConsumerController service ok  >>  producer >>"+s;
    }


    @GetMapping("m5")
    public String method5(User user){

        System.out.println("user = " + user);

        String s = producerClient.method5(user);
        return "ConsumerController service ok  >>  producer >>"+s;
    }

    @GetMapping("m6")
    public String method6(Integer[] ids){
        String s = producerClient.method6(ids);
        return "ConsumerController service ok  >>  producer >>"+s;
    }

    @GetMapping("m7")
    public ResponseResult method7(){

        // openfeign发起请求后 得到响应 是否可以完成结果类型的自动转化
        ResponseResult responseResult = producerClient.method7();

        return responseResult;
    }
}
